package com.pl.rabarbar.old.stuff.need.to.be;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;



public class ThreadListener implements ServletContextListener {

	
	private Deamon deamon;
	private ListObserver to;
	public ListObserver getTo() {
		return to;
	}

	public Deamon getDeamon() {
		return deamon;
	}

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
this.deamon.getThread().interrupt();

	}
	
	@Override
	public void contextInitialized(ServletContextEvent e) {
		ServletContext cntx = e.getServletContext();
		// TODO Auto-generated method stub
		this.deamon.setThread(new Thread(deamon));
		this.deamon.getThread().start();
		
//		this.to = new ListObserver(this.deamon);
//	    this.deamon.addObserver(to);
//	    cntx.setAttribute("ListObserver", to);
		System.out.println("deamon started and it's observer");
	}

}
